"use strict";
cc._RF.push(module, '4564977GOJNzrPU7z6q3qmK', 'DogoerFixMode');
// Script/dogoer/DogoerFixMode.ts

Object.defineProperty(exports, "__esModule", { value: true });
var Constant_1 = require("../constant/Constant");
// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var DogerFixed = /** @class */ (function (_super) {
    __extends(DogerFixed, _super);
    function DogerFixed() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.rightDogoer = null;
        _this.leftDogoer = null;
        _this.addScore = null;
        _this.leftObj = null;
        _this.rightObj = null;
        _this.kind = "twoSide";
        return _this;
    }
    DogerFixed.prototype.start = function () {
        this.leftDogoer = cc.find("leftdog", this.node);
        this.rightDogoer = cc.find("rightdog", this.node);
        this.node.y = Constant_1.Constant.SCREEN.height / 2;
        switch (this.kind) {
            case "twoSide":
                this.autoFixed(this.rightDogoer, 1);
                this.autoFixed(this.leftDogoer, 2);
                break;
            case "left":
                this.autoFixed_left(this.rightDogoer, 1);
                this.autoFixed_left(this.leftDogoer, 2);
                break;
            case "right":
                this.autoFixed_right(this.rightDogoer, 1);
                this.autoFixed_right(this.leftDogoer, 2);
                break;
        }
        this.addScore.getComponent(cc.BoxCollider).size.width = Constant_1.Constant.SCREEN.width;
    };
    // onLoad () {}
    DogerFixed.prototype.autoFixed = function (dogoer, direction) {
        var totalW = this.leftObj.width + this.rightObj.width;
        var screenW = Constant_1.Constant.SCREEN.width;
        var length = dogoer.width = (screenW - totalW) / 2;
        dogoer.getComponent(cc.BoxCollider).size.width = length;
        dogoer.height = dogoer.getComponent(cc.BoxCollider).size.height;
        switch (direction) {
            case 1: //右边
                dogoer.x = (screenW - length) / 2;
                break;
            case 2: //左边
                dogoer.x = -(screenW - length) / 2;
                break;
            default:
                break;
        }
    };
    DogerFixed.prototype.autoFixed_right = function (dogoer, direction) {
        var totalW = this.leftObj.width + this.rightObj.width;
        var screenW = Constant_1.Constant.SCREEN.width;
        var length = dogoer.width = (screenW - totalW) / 2;
        dogoer.getComponent(cc.BoxCollider).size.width = length;
        dogoer.height = dogoer.getComponent(cc.BoxCollider).size.height;
        switch (direction) {
            case 1: //右边
                dogoer.x = -(screenW - length) / 2;
                break;
            case 2: //左边
                dogoer.x = -(screenW - 3 * length) / 2;
                break;
            default:
                break;
        }
    };
    DogerFixed.prototype.autoFixed_left = function (dogoer, direction) {
        var totalW = this.leftObj.width + this.rightObj.width;
        var screenW = Constant_1.Constant.SCREEN.width;
        var length = dogoer.width = (screenW - totalW) / 2;
        dogoer.getComponent(cc.BoxCollider).size.width = length;
        dogoer.height = dogoer.getComponent(cc.BoxCollider).size.height;
        switch (direction) {
            case 1: //右边
                dogoer.x = (screenW - length) / 2;
                break;
            case 2: //左边
                dogoer.x = (screenW - 3 * length) / 2;
                break;
            default:
                break;
        }
    };
    DogerFixed.prototype.onLoad = function () {
    };
    DogerFixed.prototype.update = function (dt) {
        this.movingPlaneBySpeed(dt);
    };
    DogerFixed.prototype.movingPlaneBySpeed = function (dt) {
        var t = this;
        var movingNode = t.node;
        if (movingNode.y < -Constant_1.Constant.SCREEN.height) {
            movingNode.active = false;
            movingNode.y = Constant_1.Constant.SCREEN.height / 2;
        }
        else {
            var action = cc.moveBy(dt, new cc.Vec2(0, -Constant_1.Constant.GAME_SPEED / 2));
            movingNode.runAction(action);
        }
    };
    __decorate([
        property(cc.Node)
    ], DogerFixed.prototype, "rightDogoer", void 0);
    __decorate([
        property(cc.Node)
    ], DogerFixed.prototype, "leftDogoer", void 0);
    __decorate([
        property(cc.Node)
    ], DogerFixed.prototype, "addScore", void 0);
    __decorate([
        property(cc.Node)
    ], DogerFixed.prototype, "leftObj", void 0);
    __decorate([
        property(cc.Node)
    ], DogerFixed.prototype, "rightObj", void 0);
    __decorate([
        property
    ], DogerFixed.prototype, "kind", void 0);
    DogerFixed = __decorate([
        ccclass
    ], DogerFixed);
    return DogerFixed;
}(cc.Component));
exports.default = DogerFixed;

cc._RF.pop();